import { createStore } from "vuex";
import VuexPersist from "vuex-persist";
import data from '../assets/tabs.json'
const vuexLocal = new VuexPersist({
    storage: window.localStorage,
})
export default createStore({
    state: {
        unread: data.unread,
        read: data.read,
        recycle: data.recycle
    },
    mutations: {
        addread(state, index) {
            state.read.push(state.unread[index])
            state.unread.splice(index,1)
            
        },
        addrecycle(state, index) {
            state.recycle.push(state.read[index])
            state.read.splice(index, 1)
        },
        addunread(state, index) {
            state.read.push(state.recycle[index])
            console.log(state.recycle[index]);
            state.recycle.splice(index, 1)
        },
        allunread(state) {
            for (var i = 0; i < state.recycle.length; i++){
                state.read.push(state.recycle[i])
            }
            state.recycle=[]
        },
        allread(state) {
            for (var i = 0; i < state.unread.length; i++) {
                state.read.push(state.unread[i])
            }
            state.unread = []
        },
        allrecycle(state) {
            for (var i = 0; i < state.read.length; i++) {
                state.recycle.push(state.read[i])
            }
            state.read = []
        },
        del(state) {
            state.recycle=[]
        }


    },
    plugins: [vuexLocal.plugin],
})